package com.lkd.shoppingcart.service.impl;

import com.lkd.shoppingcart.dao.UserDao;
import com.lkd.shoppingcart.dao.impl.UserDaoImpl;
import com.lkd.shoppingcart.entity.User;
import com.lkd.shoppingcart.service.UserService;

public class UserServiceImpl implements UserService {
	
	private UserDao userDao = new UserDaoImpl();

	@Override
	public void registerUser(User user) {
		userDao.addUser(user);
	}

	@Override
	public User login(User user) {
		return userDao.queryByNameAndPassword(user.getName(), user.getPassword());
	}

	@Override
	public boolean existsUsername(String username) {
		if (userDao.queryByName(username) == null) {
			// 若没查到对应用户名的用户，则该用户名可用
			return false;
		}
		return true;
	}

}
